package com.dolphin.common.component.var.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * @author shida
 */

@Getter
public enum NaturePeriodTypeEnum {
    UNSET("未设置","NOTSET", 0, 0),
    NATURE_HOUR("时","HOUR", 60 * 60 * 1000L, 1),
    NATURE_DAY("日","DAY", 24 * 3600 * 1000L, 1),
    NATURE_WEEK("周","WEEK", 7 * 24 * 3600 * 1000L, 1),
    NATURE_MONTH("月","MONTH", 31 * 24 * 3600 * 1000L, 1)
    ;

    private String code;
    private String description;
    private Integer id;
    private long time;

    NaturePeriodTypeEnum(String code, String description, long time, Integer id) {
        this.code = code;
        this.description = description;
        this.id = id;
        this.time = time;
    }

    public static NaturePeriodTypeEnum formString(String naturePeriodType){
        if(StringUtils.isEmpty(naturePeriodType)){
            return null;
        }

        for(NaturePeriodTypeEnum item : values()){
            if(item.name().equals(naturePeriodType)){
                return item;
            }
        }

        throw new RuntimeException("Unsupported NaturePeriodTypeEnum:" + naturePeriodType);
    }
}
